﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpServer
{
    public partial  class HttpResponse
    {
        public byte[] Header { get; set; }
        public byte[] Body { get; set; }

        public HttpResponse (HttpReqeust hrReqeust)
        {
//            HTTP/1.1 200 OK
//Server: nginx
//Date: Mon, 08 Jun 2015 13:57:37 GMT
//Content-Type: text/html; charset=utf-8
//Transfer-Encoding: chunked
//Connection: keep-alive
//Vary: Accept-Encoding
//Content-Encoding: gzip

            if (hrReqeust.Url==null)
            {
                return;
            }
            StringBuilder sb=new StringBuilder();
            sb.Append("HTTP/1.1 200 OK");
            sb.Append("Date: " + DateTime.Now);
            string ext = Path.GetExtension(hrReqeust.Url);
            if (ext==".jpg")
            {
                sb.AppendLine("Content-Type: image/jpeg; charset=utf-8");
            }
            else if(ext==".txt")
            {
                sb.AppendLine("Content-Type: text/plain; charset=utf-8");
            }
            else
            {
                sb.AppendLine("Content-Type: text/html; charset=utf-8");
            }
            sb.AppendLine("");
            Header = Encoding.UTF8.GetBytes(sb.ToString());



        }
    }
}
